#include "_pch.h"
#include "MObjCatalog.h"

using namespace wh;
using namespace wh::object_catalog;



//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
MPathItem::MPathItem(const char option)
	:TModelData<rec::PathItem>(option)
{
}

//-------------------------------------------------------------------------
bool MPathItem::GetSelectQuery(wxString& query)const
{
	auto path = dynamic_cast<MPath*>(this->mParent);
	auto catalog  = dynamic_cast<MObjCatalog*>(path->GetParent());
	const auto& data = catalog->GetData();
	query = wxString::Format(
		" SELECT _id, _obj_label, NULL AS _cls_id, _class_label "
		" FROM fget_objnum_pathinfo_table(%s)"
		, data.mObj.mID
		);
	return true;
}
//-------------------------------------------------------------------------
bool MPathItem::LoadThisDataFromDb(std::shared_ptr<whTable>& table, const size_t row)
{
	T_Data data;
	table->GetAsString(0, row, data.mObj.mID);
	table->GetAsString(1, row, data.mObj.mLabel);
	table->GetAsString(2, row, data.mCls.mID);
	table->GetAsString(3, row, data.mCls.mLabel);
	SetData(data);
	return true;
};





//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
bool MPath::GetSelectChildsQuery(wxString& query)const
{
	auto catalog = dynamic_cast<MObjCatalog*>(this->GetParent());
	

	if (catalog)
	{
		const auto& data = catalog->GetData();

		query = wxString::Format(
			" SELECT _id, _obj_label, NULL AS _cls_id, _class_label "
			" FROM fget_objnum_pathinfo_table(%s)"
			, data.mObj.mID
			);
		return true;
	}
	return false;
}
